//
//  SHD_NOImageCell.m
//  B段项目
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "SHD_NOImageCell.h"

@implementation SHD_NOImageCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _userImageView = [[UIImageView alloc]init];
        _userNameLabel = [[UILabel alloc]init];
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = [UIColor grayColor];
        _midImageView = [[UIImageView alloc]init];
        _contectLabel = [[myContectLabel alloc]init];
        _likeLabel = [[UILabel alloc]init];
        _likeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_userImageView];
        [self.contentView addSubview:_userNameLabel];
        [self.contentView addSubview:_timeLabel];
        [self.contentView addSubview:_midImageView];
        [self.contentView addSubview:_contectLabel];
        [self.contentView addSubview:_likeLabel];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _userImageView.frame = CGRectMake(15 * FitWidth, 15 * FitHeight, 40 * FitWidth, 40 * FitHeight);
    _userImageView.layer.cornerRadius = 20 * FitHeight;
    _userNameLabel.frame = CGRectMake(_userImageView.frame.size.width + _userImageView.frame.origin.x + 10 * FitWidth, 30 *FitHeight, 100 * FitWidth, 10 * FitHeight);
    _timeLabel.frame = CGRectMake(325 * FitWidth, _userNameLabel.frame.origin.y, 40 * FitWidth, 10 *FitHeight);
    _contectLabel.numberOfLines = 0;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:18 * FitWidth], NSFontAttributeName, nil];
    CGRect rect = [_chipModel.content boundingRectWithSize:CGSizeMake(345 * FitWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _contectLabel.frame = CGRectMake(_userImageView.frame.origin.x, _userImageView.frame.origin.y + _userImageView.frame.size.height + 10 * FitHeight, 345 * FitWidth, rect.size.height + 2 *  FitHeight);
    _likeLabel.frame = CGRectMake(160 * FitWidth, _contectLabel.frame.size.height + _contectLabel.frame.origin.y + 10 * FitHeight, 200 * FitWidth, 10 * FitHeight);
    UITapGestureRecognizer *tap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userVc)];
    [_userImageView addGestureRecognizer:tap];
    _userImageView.userInteractionEnabled = YES;
}
-(void)userVc
{
    SHD_UserDataViewController *suv = [[SHD_UserDataViewController alloc]init];
    suv.ID = [_chipModel.userinfo objectForKey:@"uid"];
    [self.nav pushViewController:suv animated:YES];
    
    
    
}
-(void)setChipModel:(SHD_ChipMainModel *)chipModel
{
    _chipModel = chipModel;
    
    [_userImageView sd_setImageWithURL:[NSURL URLWithString:[chipModel.userinfo objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"SHD_Cov"]];
    _userImageView.layer.masksToBounds = YES;
    _userImageView.layer.cornerRadius = 20 * FitWidth;
    _userImageView.clipsToBounds = YES;
    
    _timeLabel.text = chipModel.addtime_f;
    _timeLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:10 * FitWidth];
    _timeLabel.textAlignment = 2;
    _contectLabel.text = chipModel.content;
    _likeLabel.text = [NSString stringWithFormat:@"评论:%@          喜欢:%@", [chipModel.counterList objectForKey:@"comment"], [chipModel.counterList objectForKey:@"like"]];
    _likeLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:10 * FitWidth];
    _likeLabel.textAlignment = 2;
    _userNameLabel.text = [chipModel.userinfo objectForKey:@"uname"];
    _userNameLabel.font = [UIFont systemFontOfSize:15];
    [_userNameLabel NightWithType:UIViewColorTypeNormal];
    
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
